<?php include template('header','common');?>
<link rel="stylesheet" type="text/css" href="{__ROOT__}template/default/statics/css/index.css?v={HD_VERSION}">
<link rel="stylesheet" type="text/css" href="{__ROOT__}template/default/statics/css/callNames.css?v={HD_VERSION}">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css">
<style>
.tag-no{font-size:14px; color:#999; border:1px solid #999; height:20px; line-height:20px; padding:0 5px; float:left; margin:3px 5px;}
.tag-yes{font-size:14px; color:#97c619; border:1px solid #97c619; height:20px; line-height:20px; padding:0 5px; float:left; margin:3px 5px;}
</style>
<div class="mask"></div>
<div class="pinlun" style="display:none;">
	<div class="edit">取消</div>
	<div class="top">
		<img src="" alt="">
		<span></span>
	</div>
	<div class="ping-star">
		<div class="star-item">
			<label>吃饭</label>
			<select id="example-fontawesome" name="rating">
				<option value="1">1</option>
				<option value="2">2</option>
				<option value="3">3</option>
				<option value="4">4</option>
				<option value="5">5</option>
			</select>
		</div>
		<div class="star-item">
			<label>睡觉</label>
			<select id="example-fontawesome1" name="rating">
				<option value="1">1</option>
				<option value="2">2</option>
				<option value="3">3</option>
				<option value="4">4</option>
				<option value="5">5</option>
			</select>
		</div>
		<div class="star-item">
			<label>纪律</label>
			<div style="width:80%;">
			<font class="tag tag-no">喧哗</font>
			<font class="tag tag-no">追赶</font>
			<font class="tag tag-no">打架</font>
			<font class="tag tag-no">脏话</font>
			<font class="tag tag-no">未准时到班</font>
			<font class="tag tag-no">拿动他人物品</font>
			<font class="tag tag-no">乱扔垃圾</font>
			<font class="tag tag-no">恶作剧</font>
			<input type="text" name="other" value="" style="margin-left:5px;" placeholder="其它可编辑" />
			</div>
		</div>
		<input type="hidden" name="mealNum" value="3">
		<input type="hidden" name="bedNum" value="3">
		<input type="hidden" name="student_id" value="">
	</div>
	<div class="bottom" style="padding-left:10px;">
		请老师于当天15:30之前完成对孩子的打分
	</div>
	<button class="mask-btn">提交</button>
</div>
<div class="container">
	<?php foreach($students as $k => $v){?>
	<div class="items-box {if $v['leave'] > 0}leaved{/if}">
		<div class="avatar">
			<img src="{$v['head']}" alt="">
		</div>
		<div class="name">{$v['truename']}<br />{$v['classname']}班</div>
		<div class="mark-items">
			{if $v['leave'] > 0}
			<span>已请假</span>
			<span>打分</span>
			{else}
				{if $v['point'] > 0}
				<span class="point arrived" sid="{$v['id']}">已到</span>
				{else}
				<span class="point" sid="{$v['id']}">点到</span>
				{/if}
				{if $v['iscoring'] > 0}
				<span class="scoring marked" mealNum="{$v['scoring']['mealNum']}" bedNum="{$v['scoring']['bedNum']}" disciplineNum="{$v['scoring']['disciplineNum']}" id="scoring{$v['id']}" sid="{$v['id']}" head="{$v['head']}" truename="{$v['truename']}">已打分</span>
				{else}
				<span class="scoring" mealNum="{$v['scoring']['mealNum']}" bedNum="{$v['scoring']['bedNum']}" disciplineNum="{$v['scoring']['disciplineNum']}" id="scoring{$v['id']}" sid="{$v['id']}" head="{$v['head']}" truename="{$v['truename']}">打分</span>
				{/if}
			{/if}
		</div>
	</div>
	<?php }?>
	<div style="height:80px; width:100%; position:relative;overflow: hidden; display: flex;"></div>
</div>
<script src="{__ROOT__}template/default/statics/js/jquery.barrating.js"></script>
<script>
	$(".point").click(function(){
		var id = $(this).attr('sid');
		var _this = $(this);
		var ajaxurl="<?php echo url('member/index/point')?>";
		$.post(ajaxurl,{'student_id':id},function(ret){
			if(ret.status == 1){
				if(ret.result == 1){
					_this.addClass("arrived");
					_this.text('已到');
				}else{
					_this.removeClass('arrived');
					_this.text('点到');
				}
			}else{
				alerts(ret.message);
			}
		},'json');
	});
	
	$(".mask-btn").click(function(){
		var student_id = $("[name='student_id']").val();
		var mealNum = $("[name='mealNum']").val();
		var bedNum = $("[name='bedNum']").val();
		var other = $("[name='other']").val();
		var disciplineNum = '';
		$(".tag-yes").each(function(){
			disciplineNum += $(this).text()+",";
		});
		if(other){
			disciplineNum += other;
		}
		
		var _this = $(this);
		var ajaxurl="<?php echo url('member/index/scoring')?>";
		$.post(ajaxurl,{'student_id':student_id,'mealNum':mealNum,'bedNum':bedNum,'disciplineNum':disciplineNum},function(ret){
			if(ret.status == 1){
				$("#scoring"+student_id).addClass("marked");
				$("#scoring"+student_id).text('已打分');
				$("#scoring"+student_id).attr('mealNum',mealNum);
				$("#scoring"+student_id).attr('bedNum',bedNum);
				$("#scoring"+student_id).attr('disciplineNum',disciplineNum);
				$(".mask").hide();
		        $(".pinlun").slideUp();
				$(".tag").removeClass('tag-yes').addClass('tag-no');
			}else{
				alerts(ret.message);
			}
		},'json');
	});
	$(".tag").click(function(){
		if($(this).hasClass('tag-no')){
			$(this).removeClass('tag-no').addClass('tag-yes');
		}else{
			$(this).removeClass('tag-yes').addClass('tag-no');
		}
	});
	function ratingEnable() {
            $('#example-fontawesome').barrating({
                theme: 'fontawesome-stars',
				initialRating:3,
                showSelectedRating: true,
				onSelect:function(value, text){
					$("[name='mealNum']").val(value);
				}
            });
            $('#example-fontawesome1').barrating({
                theme: 'fontawesome-stars',
				initialRating:3,
                showSelectedRating: false,
				onSelect:function(value, text){
					$("[name='bedNum']").val(value);
				}
            });
        }
    $(function () {
		function ratingEnable() {
            $('#example-fontawesome').barrating({
                theme: 'fontawesome-stars',
				initialRating:3,
                showSelectedRating: true,
				onSelect:function(value, text){
					$("[name='mealNum']").val(value);
				}
            });
            $('#example-fontawesome1').barrating({
                theme: 'fontawesome-stars',
				initialRating:3,
                showSelectedRating: false,
				onSelect:function(value, text){
					$("[name='bedNum']").val(value);
				}
            });
        }      
		ratingEnable();    
		$(".edit").click(function(){
			$(".mask").hide();
			$(".pinlun").slideUp()
		})
		$(".scoring").click(function(){
			$(".mask").show();
			$(".pinlun").slideDown();
			$("[name='student_id']").val($(this).attr('sid'));
			$(".top").find("img").attr('src',$(this).attr('head'));
			$(".top").find("span").text($(this).attr('truename'));
			$('#example-fontawesome').barrating('set', $(this).attr('mealNum'));
			$('#example-fontawesome1').barrating('set', $(this).attr('bedNum'));
			$(".tag").removeClass('tag-yes').addClass('tag-no');
			str=$(this).attr('disciplineNum'); //这是一字符串 
			var strs= new Array(); //定义一数组 
			
			strs=str.split(","); //字符分割 
			for (i=0;i<strs.length ;i++ ) 
			{
				var istatus = false;
				$(".tag").each(function(){
					if($(this).text() == strs[i]){
						$(this).removeClass('tag-no').addClass('tag-yes');
						istatus = true;
					}
				});
				if(istatus == false){
					$("[name='other']").val(strs[i]);
				} 
			} 
		});
	});
</script>
<?php include template('footer','common');?>